package main

import (
	"fmt"
//	"time"
)

type Node struct{
     left *Node 
     value int
     right *Node

}

func insert(p *Node,root **Node){

	if *root == nil {
           *root = p
	   fmt.Println("jiang",(*root).value)
	   return
	}

        if p.value > (*root).value {
                insert(p,&((*root).right))

	}else if p.value < (*root).value{
	       insert(p,&((*root).left))

	}
}

func show(p *Node){
   if p!=nil {
     fmt.Println("node value ",p.value)     
     if p.left != nil {
        show(p.left)
     }

     if p.right != nil {
        show(p.right)
     }
	
     

   }

}

var pN *Node

func test1(){

	a := [...]int{10,3,2,8,7,5}

	for i:=0 ;i<len(a);i++{

	   p1 := new(Node)
	   p1.value = a[i]
           insert(p1,&pN)

	}

        
        show(pN)

	fmt.Println("ok")

}

func test2(){

        a := [...]int{10,3,2,8,7,5}


           p1 := new(Node)
           p1.value = a[0]
        
           p2 := new(Node)
           p2.value = a[1]


           p3 := new(Node)
           p3.value = a[2]


           p4 := new(Node)
           p4.value = a[3] 
        pN = p1
        p1.left = p2
        p1.right = p3

        p3.left = p4


        show(pN)

        fmt.Println("ok",p1.left.value,p3.left.value)

}


func main(){
   test1()
}
